package cn.anecansaitin.inet.mixins;

import cn.anecansaitin.inet.TranslateHelper;
import mcjty.rftoolsbase.api.xnet.channels.Color;
import mcjty.rftoolsbase.api.xnet.gui.IEditorGui;
import mcjty.xnet.apiimpl.logic.Sensor;
import net.minecraft.world.item.ItemStack;
import org.spongepowered.asm.mixin.Final;
import org.spongepowered.asm.mixin.Mixin;
import org.spongepowered.asm.mixin.Shadow;
import org.spongepowered.asm.mixin.injection.At;
import org.spongepowered.asm.mixin.injection.Inject;
import org.spongepowered.asm.mixin.injection.callback.CallbackInfo;

@Mixin(Sensor.class)
public abstract class SensorMixin {
    @Final
    @Shadow
    private int index;
    @Shadow
    private ItemStack filter;
    @Shadow
    private Sensor.SensorMode sensorMode;
    @Shadow
    private Sensor.Operator operator;
    @Shadow
    private int amount;
    @Shadow
    private Color outputColor;

    @Inject(method = "createGui", at = @At(value = "INVOKE", target = "Lmcjty/rftoolsbase/api/xnet/gui/IEditorGui;choices(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Enum;[Ljava/lang/Enum;)Lmcjty/rftoolsbase/api/xnet/gui/IEditorGui;", ordinal = 0), remap = false, cancellable = true)
    private void mixin$createGui(IEditorGui gui, CallbackInfo ci) {
        gui
                .choices(Sensor.TAG_MODE + index, TranslateHelper.getText("inet.controller.setting.button.sensor_mode.tooltip"), sensorMode, Sensor.SensorMode.values())
                .choices(Sensor.TAG_OPERATOR + index, TranslateHelper.getText("inet.controller.setting.button.operator.tooltip"), operator, Sensor.Operator.values())
                .integer(Sensor.TAG_AMOUNT + index, TranslateHelper.getText("inet.controller.setting.label.amount.tooltip"), amount, 46)
                .colors(Sensor.TAG_COLOR + index, TranslateHelper.getText("inet.controller.setting.button.output_color.tooltip"), outputColor.getColor(), Color.COLORS)
                .ghostSlot(Sensor.TAG_STACK + index, filter)
                .nl();
        ci.cancel();
    }
}
